/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ShowTicket.java
 *
 * Created on 2009-12-7, 15:49:32
 */

package view;

/**
 *
 * @author Mark
 */
import model.InputModel;
public class ShowTicket extends javax.swing.JFrame {
    /** Creates new form ShowTicket */
    public ShowTicket() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        ticketsalerPUEntityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("ticketsalerPU").createEntityManager();
        ticketsQuery = java.beans.Beans.isDesignTime() ? null : ticketsalerPUEntityManager.createQuery("SELECT t FROM Tickets t");
        ticketsList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : ticketsQuery.getResultList();
        jScrollPane1 = new javax.swing.JScrollPane();
        ShowTicketTable = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        inputIdField = new javax.swing.JTextField();
        inputTicketsCountField = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        submin = new javax.swing.JButton();
        Cancel = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        ShowTicketTable.setColumnSelectionAllowed(true);

        org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, ticketsList, ShowTicketTable);
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${id}"));
        columnBinding.setColumnName("Ticket Id");
        columnBinding.setColumnClass(Integer.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${tfrom}"));
        columnBinding.setColumnName("From");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${tfromtime}"));
        columnBinding.setColumnName("Start Time");
        columnBinding.setColumnClass(java.util.Date.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${tarrive}"));
        columnBinding.setColumnName("Arrite");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${tarrivetime}"));
        columnBinding.setColumnName("Arrive Time");
        columnBinding.setColumnClass(java.util.Date.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${tprice}"));
        columnBinding.setColumnName("Ticket price");
        columnBinding.setColumnClass(Integer.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${tseats}"));
        columnBinding.setColumnName("Seat left");
        columnBinding.setColumnClass(Integer.class);
        columnBinding.setEditable(false);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        jScrollPane1.setViewportView(ShowTicketTable);
        ShowTicketTable.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        ShowTicketTable.getColumnModel().getColumn(0).setResizable(false);
        ShowTicketTable.getColumnModel().getColumn(1).setResizable(false);
        ShowTicketTable.getColumnModel().getColumn(2).setResizable(false);
        ShowTicketTable.getColumnModel().getColumn(2).setPreferredWidth(150);
        ShowTicketTable.getColumnModel().getColumn(3).setResizable(false);
        ShowTicketTable.getColumnModel().getColumn(4).setResizable(false);
        ShowTicketTable.getColumnModel().getColumn(4).setPreferredWidth(150);
        ShowTicketTable.getColumnModel().getColumn(5).setResizable(false);
        ShowTicketTable.getColumnModel().getColumn(6).setResizable(false);

        jLabel1.setText("please enter the ticket id to buy:");

        inputIdField.setColumns(5);

        inputTicketsCountField.setColumns(10);

        jLabel2.setText("counts:");

        submin.setText("Buy!");
        submin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                subminActionPerformed(evt);
            }
        });

        Cancel.setText("Cancel");
        Cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 782, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(inputIdField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(inputTicketsCountField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(submin)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 290, Short.MAX_VALUE)
                        .addComponent(Cancel)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 331, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(inputIdField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(inputTicketsCountField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(submin)
                    .addComponent(Cancel))
                .addContainerGap(30, Short.MAX_VALUE))
        );

        bindingGroup.bind();

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-800)/2, (screenSize.height-424)/2, 800, 424);
    }// </editor-fold>//GEN-END:initComponents

    private void subminActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_subminActionPerformed
           new ucm.UCBuyTickets(this).run();
            inputIdField.requestFocusInWindow();
            ShowTicket.this.dispose();

    }//GEN-LAST:event_subminActionPerformed

    private void CancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CancelActionPerformed
              new ucm.UCDispalyTicketsaler();
            ShowTicket.this.dispose();
    }//GEN-LAST:event_CancelActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Cancel;
    private javax.swing.JTable ShowTicketTable;
    private javax.swing.JTextField inputIdField;
    private javax.swing.JTextField inputTicketsCountField;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton submin;
    private java.util.List<view.Tickets> ticketsList;
    private javax.persistence.Query ticketsQuery;
    private javax.persistence.EntityManager ticketsalerPUEntityManager;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
   public InputModel getinputModel() {
        InputModel user = new InputModel();
        user.setUserInput(inputIdField.getText());
        user.setticketcount(inputTicketsCountField.getText());
        return user;
    }

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ShowTicket().setVisible(true);
            }
        });
    }


}
